/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_gemport_mapping.h

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	wayne.lee	2012/7/28	Create
*/

#ifndef  _OMCI_GEM_PORT_MAPPING_H_
#define _OMCI_GEM_PORT_MAPPING_H_
#include <stdint.h>
#include <netinet/in.h>
#include "omci_adpt_common.h"
#include "libgponmap.h"

//#define OMCI_GEM_PORT_MAPPING_DEBUG  1

#define MAX_GEM_PORT_MAPPING_RULE_NUM	8192 //max rule num in gem port mapping 

/*9.3.10 */
#define OMCI_GEMPORT_MAPPING_UNTAGGED_FLAG		0
#define OMCI_GEMPORT_MAPPING_TAGGED_FLAG		1
#define MAX_OMCI_PBIT_GPORT_ITEM_LEN			3
#define MAX_OMCI_PBIT_GPORT_LEN					3
#define MAX_OMCI_PBIT_NUM							8

#define MAX_OMCI_DSCP_KINDS						64	
#define MAX_OMCI_DSCP_PBIT_GPORT_ITEM_LEN		4
#define MAX_OMCI_DSCP_PBIT_GPORT_LEN		    (MAX_OMCI_DSCP_PBIT_GPORT_ITEM_LEN * MAX_OMCI_DSCP_KINDS)



#define OMCI_GEMPORT_MAPPING_TAGFLAG			(1<<0)
#define OMCI_GEMPORT_MAPPING_USERPORT			(1<<1)
#define OMCI_GEMPORT_MAPPING_ANI_PORT			(1<<2)
#define OMCI_GEMPORT_MAPPING_VID					(1<<3)
#define OMCI_GEMPORT_MAPPING_DSCP				(1<<4)
#define OMCI_GEMPORT_MAPPING_PBIT				(1<<5)
#define OMCI_GEMPORT_MAPPING_GEMPORT 			(1<<6)
#define OMCI_GEMPORT_MAPPING_CLASSID_INSTID		(1<<7)
#define OMCI_GEMPORT_MAPPING_TAGCTL				(1<<8)
#if/*TCSUPPORT_COMPILE*/ defined(TCSUPPORT_GOOGLE_FIBER)
#define OMCI_GEMPORT_MAPPING_DEF_PBIT			(1<<9)
#endif/*TCSUPPORT_COMPILE*/


#define MAX_GEMPORT_VALID_MEID_NUM				3

#define OMCI_GEMPORT_RULE_FREE_FLAG1 			1
#define OMCI_GEMPORT_RULE_FREE_FLAG0 			0

typedef struct omciGemPortMapping_s{
	struct omciGemPortMapping_s *next;
	uint16_t index;
/*tagctl: if the bit value is 1, then this bit function is valid in this rule.
	bit		description
	0		tag flag, 0:untagged, 1:tagged
	1		user port
	2		ani port
	3		vid
	4		dscp
	5		pbit
	6		gem port
	7		ME id (class id+instance id)
	8~15	reserved
*/	
	uint16_t tagctl;
	uint8_t tagFlag;//0:untagged,1:tagged
	uint8_t userPort;//0xff: this value indicates all user ports.
	uint16_t aniPort;	
	uint16_t vid;
	uint8_t dscp;
	uint8_t pbit;
	uint16_t gemPort;	
	uint32_t classIdInstId;//classid+instance id
}omciGemPortMapping_t, *omciGemPortMapping_ptr;

/*******************************************************************************************************************************
general function

********************************************************************************************************************************/
int convertGemPortRule(IN omciGemPortMapping_ptr srcRule_ptr, OUT gemPortMappingIoctl_ptr destRule_ptr);
int addConvertedGemPortRule(IN omciGemPortMapping_ptr  rule_ptr);
int delConvertedGemPortRule(IN omciGemPortMapping_ptr  rule_ptr);
int findOmciGemPortMappingRule(omciGemPortMapping_ptr rule_ptr, uint16_t * index);
int modifyOmciGemPortMappingRule(uint16_t modifyFlag, omciGemPortMapping_ptr oldRule_ptr, omciGemPortMapping_ptr newRule_ptr);
int getOmciGemPortMappingRuleMaxIndex(uint16_t * maxIndex);
int addOmciGemPortMappingRule(omciGemPortMapping_ptr rule_ptr);
int addOmciGemPortMappingRuleByUni(uint8_t userPort, uint32_t classIdInstId, uint32_t *meIdArr, uint8_t validNum);
int delOmciGemPortMappingRuleByMatchFlag(uint16_t delMatchFlag, omciGemPortMapping_ptr currMappingRule);
int modifyOmciGemPortMappingRuleByUnmarkOpt(uint8_t flag, uint16_t length, uint8_t *val, uint32_t classIdInstId);
int delGemPortMappingUntagRuleByUntagAction(uint16_t currInstanceId);
void displayOmciCurrGemPortMappingRule();
void clearOmciGemportRule(void);

extern omciGemPortMapping_ptr gemPortMapping_ptr;
#endif
